using System;
using UnityEngine.UIElements;

namespace DA.AnimGraph.Editor {

    internal abstract class InspectorField : VisualElement {
        public string labelText;
        public abstract void Init(string label, object source, AGEContext ageContext, Action inspectorChangeCallback);
    }


    internal abstract class InspectorField<T> : InspectorField where T : class {
        protected T source;
        protected AGEContext ageContext;
        protected Action inspectorChangeCallback;

        public override void Init(string label, object source, AGEContext ageContext, Action inspectorChangeCallback) {
            D.A(source is T or null, "InspectorField 传入数据类型错误");
            Init(label, source as T, ageContext, inspectorChangeCallback);
        }
        public void Init(string label, T source, AGEContext ageContext, Action inspectorChangeCallback) {
            this.source = source;
            this.ageContext = ageContext;
            this.inspectorChangeCallback = inspectorChangeCallback;
            labelText = label;
            ClearUI();
            BuildUI();
            DrawUI();
        }

        protected virtual void BuildUI() { }
        protected virtual void DrawUI() { }
        protected virtual void ClearUI() {
            Clear();
        }
    }
}
